package com.bf.electroplating.controller;

import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.attachment.AttachmentVo;
import com.bf.electroplating.service.PubAttachmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.Setter;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 * (附件表)PUB_ATTACHMENT 前端控制器
 * </p>
 *
 * @author xxx
 * @since 2024-10-18
 */
@RestController
@RequestMapping("/pub-attachment")
@Tag(name = "文件管理", description = "文件管理")
@Setter(onMethod_ = @Resource)
public class PubAttachmentController {

	private PubAttachmentService iPubAttachmentService;

	@GetMapping("/download")
	@Operation(summary = "根据文件id下载文件", description = "根据文件id下载文件")
	public void download(@RequestParam("id") String id, HttpServletResponse response) throws Exception{
		iPubAttachmentService.download(id, response);
	}

	@PostMapping("/uploadFile")
	@Operation(summary = "上传文件", description = "上传文件")
	public ResultVO<AttachmentVo> uploadFile(MultipartFile file) throws IOException {
		return iPubAttachmentService.uploadFile(file);
	}

	@GetMapping("/getFileUrl")
	@Operation(summary = "根据文件id获取文件地址", description = "根据文件id获取文件地址")
	public ResultVO<String> getFileUrl(@RequestParam("id") String id) {
		return iPubAttachmentService.getFileUrl(id);
	}


}
